package com.zrrd.comparable;

import java.util.TreeSet;

/**
 * @author WanJl
 * @version 1.0
 * @title MyTreeSet
 * @description
 * @create 2024/4/21
 */
public class MyTreeSet {
    public static void main(String[] args) {
        //创建一个TreeSet集合，存学生对象
        TreeSet<Student> set=new TreeSet<>();
        //创建学生对象，并且通过构造方法传递实参，为name和age赋值
        Student s1 = new Student("张一", 66);
        Student s2 = new Student("张二", 35);
        Student s3 = new Student("钱三", 25);
        Student s4 = new Student("丁四", 25);
        Student s5 = new Student("李五", 95);
        Student s6 = new Student("王六", 15);
        //将学生对象作为集合元素，添加到TreeSet集合
        set.add(s1);
        set.add(s2);
        set.add(s3);
        set.add(s4);
        set.add(s5);
        set.add(s6);

        //遍历TreeSet集合
        set.forEach(System.out::println);

    }
}
